﻿using Reservoir.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reservoir.DAL
{
    public class RecordDAL
    {
        /// <summary>
        /// 查询记录表信息
        /// </summary>
        /// <returns></returns>
        ReservoirDbContent DbContent = new ReservoirDbContent();
        public List<TBRecord> GetTBRecord()
        {
            var list = DbContent.TBRecord.ToList();
            return list;
        }
        public List<TBRecord> GetByTBRecord(string UserId)
        {
            var list = DbContent.TBRecord.Where(r => r.UserId == UserId).ToList();
            return list;
        }
        /// <summary>
        /// 添加水库
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public int AddRecord(TBRecord record)
        {
            using (ReservoirDbContent db = new ReservoirDbContent())
            {
                // 更新到数据库
                db.Entry(record).State = EntityState.Added;
                // 返回结果
                return db.SaveChanges();
            }
        }
        /// <summary>
        /// 删除水库
        /// </summary>
        /// <param name="id">Id</param>
        public int DeleteVideo(int Id)
        {
            // 从数据库删除
            TBRecord record = DbContent.TBRecord.FirstOrDefault(r => r.Id == Id);
            DbContent.Entry(record).State = EntityState.Deleted;
            int res = DbContent.SaveChanges();
            return res;
        }
    }
}
